/**
 * 调拨单打印
 */
var style = "<style>\
		.print_template{}\
		.tables{ border:1px solid #000;border-width:1px 0 0 1px; border-collapse:collapse; width:99%;}\
		.caption{ font-size: 16px; padding-bottom: 10px; text-align:center;}\
		.tables tbody {}\
		.tables tbody td{border:1px solid #000;border-width:0 1px 1px 0; padding:2px; color:#333; line-height: 1.3; font-size: 10px;}\
		.tables tfoot td{ font-size: 11px; color: #666d70; padding-top: 10px;}\
		.tables tfoot #fmobile{ text-align: right;}\
		.notables{width: 100%; margin-top: 10px; color: #000; font-size: 10px;}\
		.notables td{font-size: 10px;line-height:20px; height:22px;white-space: nowrap; padding:0px; margin:0px;}\
		.notables .w100{ width:100%;}\
		.notables td span{ border-bottom:1px solid #000; width:60px; display:block;height:20px; text-align:left;overflow:hidden}\
		.topnotables{ margin-top: 0px;}\
		.topnotables td span{width:160px;}\
		.text-align-left{text-align: left;}\
		.text-align-center{text-align: center; font-size: 12px; margin-top: 10px;}\
		</style>";

var innerhtml = '<div class="print_template">\
		<div class="caption">'+ WG.name +'调拨单</div>\
	<table class="notables topnotables" id="topnotables">\
	  <tr><td id="number"></td>\
	    <td id="created_at"></td>\
	    <td id="formdepname"></td>\
	    <td id="todepname"></td>\
      </tr>\
      <tr><td id="operator_name"></td>\
	    <td id="product_number"></td>\
	    <td id="remarks" colspan="2"></td>\
      </tr>\
	</table>\
    <table class="tables">\
      <tr><td class="text-align-left">商品名称</td><td>属性</td><td>数量</td><td>单位</td><td>零售价</td</tr>\
      <tbody id="databody"></tbody>\
    </table>\
    <div class="text-align-center" id="pager"></div>\
	</div>';
function createAllocationPrinter(d) {
    if(d == null) {
        layer.msg('没有可打印数据');return false;
    }
    var jqueryHtml = $(innerhtml);
    jqueryHtml.find('[id="number"]').text(d.number);
    jqueryHtml.find('[id="created_at"]').text(d.created_at);
    jqueryHtml.find('[id="formdepname"]').text(d.formdepname);
    jqueryHtml.find('[id="todepname"]').text(d.todepname);
    jqueryHtml.find('[id="operator_name"]').text(d.operator_name);
    jqueryHtml.find('[id="product_number"]').text(d.product_number);
    jqueryHtml.find('[id="remarks"]').text(d.remarks);

    var tableBody = [];
    var nowPage = 1;
    var forkey = 0;
    var limit = 15;
    var total = Math.ceil(d.datalist.length / limit);
    $.each(d.datalist, function (idx, value) {
        forkey++;
        var _h = [];
        _h.push('<tr>');
        _h.push('<td class="text-align-left">'+ productGroupName(value.Products) +'</td>');
        switch (value.Products.TypeId) {
            case 10:
                _h.push('<td>'+ value.Snd.sph +'/'+ value.Snd.cyl +'</td>');
                break;
            case 20:
                _h.push('<td>'+ value.Snd.sph +'/'+ value.Snd.cyl +'</td>');
                break;
            case 30:
                _h.push('<td>'+ value.Snd.model +'/'+ value.Snd.color+'/'+ value.Snd.size +'</td>');
                break;
            case 40:
                _h.push('<td>'+ value.Snd.sph +'/'+ value.Snd.add +'</td>');
                break;
            case 41:
                _h.push('<td>'+ value.Snd.model +'/'+ value.Snd.model +'/'+ value.Snd.size +'/'+ value.Snd.film_color +'</td>');
                break;
            case 50:
                _h.push('<td></td>');
                break;
            case 60:
                _h.push('<td></td>');
                break;
        }
        _h.push('<td>'+ value.AllocationNum +'</td>');
        _h.push('<td>'+ value.Products.Unit +'</td>');
        _h.push('<td>'+ value.Inventory.suggested_price +'</td>');
        _h.push('</tr>');
        tableBody.push(_h.join(''));
        if(forkey % limit == 0) {
            LODOP.NewPage();
            jqueryHtml.find('[id="databody"]').html('').html(tableBody.join(''));
            jqueryHtml.find('[id="pager"]').html(nowPage + '/'+total);
            if(nowPage > 1) {
                jqueryHtml.find('[id="topnotables"]').remove();
            }
            LODOP.ADD_PRINT_HTM(5,5,"100%","100%",style + '<body>' + jqueryHtml.html() + '</body>');
            tableBody = [];
            nowPage++;
        }
    });
    LODOP.NewPage();
    jqueryHtml.find('[id="databody"]').html('').html(tableBody.join(''));
    jqueryHtml.find('[id="pager"]').html(total + '/'+total);
    LODOP.ADD_PRINT_HTM(5,5,"100%","100%",style + '<body>' + jqueryHtml.html() + '</body>');
    LODOP.PREVIEW();
}